package com.dyz.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dyz.domain.AdminBank;
import com.dyz.model.Result;
import com.dyz.service.IAdminBankService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;

@RestController
@RequestMapping("/adminBank")
@Api(tags = "公司银行卡管理")
public class AdminBankController {
    @Resource
    private IAdminBankService adminBankService;
    @GetMapping("/getList")
    @ApiOperation(value = "获取公司银行卡列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bankCard", value = "银行卡号", dataType = "String"),
            @ApiImplicitParam(name = "realName", value = "真实姓名", dataType = "String"),
            @ApiImplicitParam(name = "current", value = "当前页码"),
            @ApiImplicitParam(name = "size", value = "每页条数"),
    })
    @PreAuthorize("hasAuthority('admin_bank_query')")
    public Result<?> getList(@ApiIgnore Page<AdminBank> page, String bankCard, String realName){
        return adminBankService.getList(page,bankCard,realName);
    }
    @PostMapping("/create")
    @ApiOperation(value = "添加公司银行卡")
    @PreAuthorize("hasAuthority('admin_bank_create')")
    public Result<?> create(@RequestBody AdminBank adminBank){
        return adminBankService.save(adminBank)?Result.success("添加成功"):Result.fail("添加失败");
    }
    @PostMapping("/update")
    @ApiOperation(value = "修改公司银行卡")
    @PreAuthorize("hasAuthority('admin_bank_update')")
    public Result<?> update(@RequestBody AdminBank adminBank){
        return adminBankService.updateById(adminBank)?Result.success("修改成功"):Result.fail("修改失败");
    }
    @GetMapping("/getOneObj")
    @ApiOperation(value = "获取公司银行卡详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键", required = true),
    })
    @PreAuthorize("hasAuthority('admin_bank_query')")
    public Result<?> getOneObj(Long id){
        return Result.success(adminBankService.getById(id));
    }
    @PostMapping("/adminUpdateStatus")
    @ApiOperation(value = "修改公司银行卡状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键", required = true),
            @ApiImplicitParam(name = "status", value = "状态", required = true)
    })
    @PreAuthorize("hasAuthority('admin_bank_update')")
    public Result<?> adminUpdateStatus(Long id,Integer status){
        return adminBankService.updateStatus(id,status);
    }
}
